
cc.Class({
    extends: cc.Component,

    properties: {
        resPokerModel:{
            default:null,
            type:cc.Prefab
        },

        bottomNode:{
            default:null,
            type:cc.Node
        },

        pokerParent:{
            default:null,
            type:cc.Node
        }
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start () {

    },

    // update (dt) {},

    initResultBottom:function (pokerArray,matchs,jokerNum) {
        matchs = [].concat(matchs)
        this.cards = pokerArray
        this.pokerParent.removeAllChildren(true)
        let pWidth = this.resPokerModel.data.width
        let pInterval = 20
        let pTotalW = 0
        for(let i=0;i<pokerArray.length;i++){
            if(i === 0)
                pTotalW = pWidth
            else pTotalW += pInterval
        }

        let leftX = -pTotalW/2 + pWidth/2
        for(let i=0;i<pokerArray.length;i++){
            let newNode = cc.instantiate(this.resPokerModel)
            newNode.x = leftX

            if(cc.gg.dataMgr.getPokerNum(pokerArray[i]) === jokerNum)
                cc.find("MixTag",newNode).active = true

            if(matchs.indexOf(pokerArray[i]) > -1){
                cc.gg.baseUtil.arrayRemove(matchs,pokerArray[i])
                cc.find("MatchTag",newNode).active = true
            }

            cc.gg.resUtil.setPokerFrameSimple(newNode.getComponent(cc.Sprite),pokerArray[i])
            this.pokerParent.addChild(newNode)
            leftX += pInterval
        }

        this.bottomNode.width = pTotalW + 20
        return pTotalW
    },

    setBottomColor:function (pokerArray,mixNum) {
        let botType = cc.gg.sortUtil.IS_SEQUENCE_ONLY_VALUE(pokerArray,mixNum)
        if(botType.isSequence){
            this.typeObj = botType
        }else {
            let isSet = cc.gg.sortUtil.isSetOnlyValue(pokerArray,mixNum)

            // cc.log("牌组：",pokerArray," isset:",isSet)
            if(isSet){
                this.typeObj = { isSet:true }
            }else if(pokerArray.length === 1 && cc.gg.dataMgr.isMixCard(pokerArray[0],mixNum)){
                this.typeObj = { isSet:true }
            }else this.typeObj = null
        }
    },

    setBottomFrame:function (botFrame) {
        if(!botFrame){
            this.bottomNode.active = false
            return
        }

        this.bottomNode.getComponent(cc.Sprite).spriteFrame = botFrame
    }
});
